package com.extrace.ui.main;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.extrace.loader.UserLoader;
import com.extrace.misc.model.UserInfo;
import com.extrace.net.IDataAdapter;

public class UserLogin extends AppCompatActivity implements View.OnClickListener, IDataAdapter<UserInfo> {
    private Button mButtonLogin;//登录按钮
    private EditText mUserID;//账号
    private EditText mPassword;//密码
    private UserLoader mLoader;
    private UserInfo mItem;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.fragment_login);
        mItem = new UserInfo();

        //获取输入的账号和密码
        mUserID=(EditText)findViewById(R.id.user_id);
        mPassword=(EditText)findViewById(R.id.user_pwd);

        mButtonLogin=(Button)findViewById(R.id.button_login);
        mButtonLogin.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        try {
            mLoader=new UserLoader(this, this);
            mLoader.Login(Integer.parseInt(mUserID.getText().toString()), mPassword.getText().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(mLoader.flag)
        {
            try {
                mLoader=new UserLoader(this, this);
                mLoader.GetUserInfo(Integer.parseInt(mUserID.getText().toString()));
            } catch (Exception e) {
                e.printStackTrace();
            }
            finish();
        }
    }

    @Override
    public UserInfo getData() {
        return mItem;
    }

    @Override
    public void setData(UserInfo data) {
        mItem = data;
    }

    @Override
    public void notifyDataSetChanged() {

    }
}
